package com.lesson4.abstractfactory.pizzastore.order;

import com.lesson4.abstractfactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/8/27 18:31
 */
public class PizzaOrder
{
    ABSFactory factory;

    public PizzaOrder(ABSFactory factory){
        setFactory(factory);
    }

    /**
    * @Description: 将抽象接口聚合进工厂类
    * @Param:  factory
    * @return:
    * @Author: 朝花不迟暮
    * @Date: 2020/9/27
    */
    public void setFactory(ABSFactory factory){
        this.factory = factory;
        Pizza pizza = null;
        String orderType="";
        do{
            orderType = getType();
            pizza = factory.createPizza(orderType);
            if(pizza !=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败！");
                break;
            }
        }while (true);
    }

    private String getType()
    {
        try
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类：");
            String line = reader.readLine();
            return line;
        } catch (IOException e)
        {
            e.printStackTrace();
            return "";
        }
    }
}
